package com.woniu40.petai_user.config;

import com.woniu40.petai_user.interceptors.Interceptor;
import com.woniu40.petai_user.interceptors.PermissionIntercepter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //设置一个映射路径  通过这个路径 转发访问  login视图   - /template/login.html
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("index").setViewName("index");
        registry.addViewController("/register.html").setViewName("register");
        registry.addViewController("/shop.html").setViewName("shop");
        registry.addViewController("/article").setViewName("article/list");
        registry.addViewController("/artcleDetails.html").setViewName("artcleDetails");
        registry.addViewController("/single-product-variable.html").setViewName("single-product-variable");

        registry.addViewController("/private-home.html").setViewName("private-home");
        registry.addViewController("/dynamic").setViewName("dynamic");
        registry.addViewController("/my-account").setViewName("my-account");
        registry.addViewController("/hospital").setViewName("hospital");
        registry.addViewController("/my-account.html").setViewName("my-account");
        registry.addViewController("/blog-details.html").setViewName("blog-details");

        registry.addViewController("/cart").setViewName("cart");
        registry.addViewController("/singleProduct").setViewName("single-product-variable");
        registry.addViewController("/shop.html").setViewName("shop");
        registry.addViewController("/about.html").setViewName("about");
        registry.addViewController("/dynamic").setViewName("dynamic");
        registry.addViewController("/addDynamic.html").setViewName("addDynamic");
        registry.addViewController("/report.html").setViewName("report");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*registry.addInterceptor(new PermissionIntercepter())
                .addPathPatterns("/**")
                .excludePathPatterns("/static/asserts/**")
                .excludePathPatterns("/imgs/**")
                .excludePathPatterns("/scripts/**")
                .excludePathPatterns("/styles/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/")
                .excludePathPatterns("/login.html");*/

        registry.addInterceptor(new Interceptor())
                .addPathPatterns("/dynamic/**")
                .addPathPatterns("/order/**")
                .addPathPatterns("/cart/**")
                .addPathPatterns("/exit");
                /*.excludePathPatterns("/static/asserts/**")
                .excludePathPatterns("/imgs/**")
                .excludePathPatterns("/scripts/**")
                .excludePathPatterns("/styles/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/")
                .excludePathPatterns("/goods/show");*/
    }

}
